import { createAxios } from '@/utils/http/axios';

enum Api {
  presigned = '/oss/presigned',
}

export interface PresignedRes {
  bucket: string;
  ossPath: string;
  fileName: string;
  method: string;
  url: string;
}

export function presignedApi(data: {
  ossPath: string;
  fileName: string;
  expiry: number;
}): Promise<PresignedRes> {
  return createAxios({
    requestOptions: {
      apiUrl: '/hc-api',
    },
  }).post({
    url: Api.presigned,
    data,
  });
}

export function upload2OSS(url: string, bin: File) {
  return fetch(url, {
    method: 'PUT',
    body: bin,
  });
}
